<template>
    <view class="add-comment paddingBottomBar">
        <view class="comment-list">
            <add-comment-item
                ref="addCommentItem"
                v-for="(item, index) in data"
                :key="index"
                :starRequired="starRequired"
                :msgRequired="msgRequired"
                :placeholder="placeholder"
                :data="item"
                @addCommentFn="addCommentFn"></add-comment-item>
        </view>
        <view class="bottom-bar">
            <button class="btn btn-main btn-fill btn-submit" @click="submit">发布</button>
        </view>
    </view>
</template>

<script>
import addCommentItem from "@/uni-sub-base/components/comment/add-comment-item.vue"

export default {
    components: {
        addCommentItem,
    },
    props: {
        data: {
            type: Array,
            default: () => [],
        },
        placeholder: {
            type: String,
            default: "请输入评论内容",
        },
        starRequired: {
            type: Boolean,
            default: true,
        },
        msgRequired: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {}
    },
    methods: {
        submit() {
            let comments = []
            let len = this.$refs.addCommentItem.length
            for (var i = 0; i < len; i++) {
                let obj = this.$refs.addCommentItem[i]
                if (obj) {
                    let param = obj.getParam()

                    if (this.starRequired && !param.star) {
                        this.easyToast("请先打分")
                        return
                    }
                    if (this.msgRequired && (!param.msg || param.msg.trim() == "")) {
                        this.easyToast("请填写评价")
                        return
                    }
                    comments.push(param)
                }
            }
            this.$emit("addCommentFn", comments)
        },
    },
}
</script>

<style lang="scss" scope>
.item-img {
    width: 700rpx;
    min-height: 300rpx;
    max-height: 700rpx;
    padding: 0;
}

.stickyTab {
    position: sticky;
    top: 44px;
    top: calc(44px + constant(safe-area-inset-top));
    top: calc(44px + env(safe-area-inset-top));
}

.btn-primary-full {
    margin-top: 72rpx;
}

.rate-model {
    display: flex;
    flex: 1;
    flex-direction: row;
    justify-content: center;

    .rate-item {
        display: flex;
        margin-right: 24rpx;
    }
}

// 评分框
.star-box {
    border-radius: 8rpx;
    background: $color-white;
    margin-bottom: 16rpx;

    .product-item {
        padding: $app-page-padding;
        display: flex;
        flex-direction: row;

        .product-img {
            width: 88rpx;
            height: 88rpx;
            border-radius: 8rpx;
        }

        .product-content {
            flex: 1;
            margin-left: 24rpx;

            .product-name {
                font-size: $font-size-30;
                font-weight: 600;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                word-break: break-all;
            }

            .product-attr {
                font-size: $font-size-24;
                color: $color-gray-3;
            }
        }
    }

    .star-item {
        border-top: 2rpx solid $uni-border-color;
        text-align: center;

        .star {
            padding: 32rpx 0;
            display: flex;
            justify-content: center;
        }

        .star-name {
            font-size: $font-size-28;
            padding-bottom: 32rpx;
            color: #dba868;
        }
    }
}

// 评价框
.evaluate-box {
    border-radius: 8rpx;
    background: $color-white;
    margin-bottom: 16rpx;
    padding: $app-page-padding;
    padding-bottom: 10rpx;

    .title {
        padding-bottom: $app-page-padding;
    }

    .textarea-box {
        position: relative;
        margin-bottom: 24rpx;

        .textarea {
            margin: 0;
            background: #f6f7f7;
            width: 100%;
            font-size: $font-size-28;
            border-radius: 8rpx;
            box-sizing: border-box;
            padding: 16rpx 24rpx 60rpx;
        }

        .textarea-toast {
            position: absolute;
            bottom: 18rpx;
            right: 24rpx;

            .currentLength {
                font-size: $font-size-24;
            }

            .maxlength {
                font-size: $font-size-20;
                color: $color-gray-C;
            }
        }
    }
}
.bottom-bar {
    .btn-submit {
        height: 90rpx;
        border-radius: 100rpx;
        margin: 0;
    }
}
</style>
